import { Body, Controller, Request, Post, Get, Query } from '@nestjs/common';
import { User } from '@/modules/User/types';
import { OrderService } from '../services/order.service';
import { CreateOrderDto } from '../dto/create_order.dto';
import { OrderListDto } from '../dto/order_list.dto';

@Controller('order')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}
  @Post('create')
  async create(@Request() req, @Body() body: CreateOrderDto) {
    try {
      const res = await this.orderService.create(req.user as User, body);
      return {
        statusCode: 200,
        message: '创建订单成功',
        data: res,
      };
    } catch (error) {
      return {
        statusCode: 500,
        message: '创建订单失败',
      };
    }
  }

  @Get('list')
  async list(@Request() req, @Query() body: OrderListDto) {
    try {
      const res = await this.orderService.list(req.user as User, body);
      return {
        message: '获取订单列表成功',
        statusCode: 200,
        data: res,
      };
    } catch (error) {
      console.log(error.message);
      return {
        message: '获取订单列表失败',
        statusCode: 500,
      };
    }
  }
}
